package com.scut.edu.wanyou.wanwanstool;

import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

import com.scut.edu.wanyou.R;


import android.content.Context;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;

public class wanwanAdapter extends BaseAdapter{
	private static final String TAG="wanwanAdapter";
	private List<Wanwan> mWanwans=new ArrayList<Wanwan>();
	private ListView mListView;
	private Context mContext;
	
	Resources resources;
	private Drawable[] drawables;
	
	public wanwanAdapter(Context context,List<Wanwan> list){
		mContext=context;
		mWanwans=list;
		
		resources=mContext.getResources();
		drawables=new Drawable[]{ resources.getDrawable(R.drawable.test_wanwanlist ), 
				resources.getDrawable(R.drawable.test_wanwanlist2 ),
				resources.getDrawable(R.drawable.test_wanwanlist3 )};
	}
	
	

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mWanwans.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return mWanwans.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}
	
	

	@Override
	public View getView(int pos, View convertView, ViewGroup arg2) {
		ViewHolder viewHolder = null;
		if (convertView == null) {
			convertView = LayoutInflater.from(mContext).inflate(
					R.layout.wanwan_listview_item, null);
			viewHolder = new ViewHolder();
			viewHolder.user_ImgView = (ImageView) convertView.findViewById(R.id.user_img);
			viewHolder.user_nicknameTextView = (TextView) convertView.findViewById(R.id.user_nickname);
			viewHolder.title=(TextView)convertView.findViewById(R.id.wanwan_title);
			viewHolder.timeTextView=(TextView)convertView.findViewById(R.id.time_textview);
			viewHolder.locationTextView=(TextView)convertView.findViewById(R.id.location_textview);
			viewHolder.detailsTextView = (TextView) convertView.findViewById(R.id.wanwan_details);
			viewHolder.imageView = (ImageView) convertView.findViewById(R.id.wanwan_pic);
			viewHolder.days_remainTextView = (TextView) convertView.findViewById(R.id.remain_days);
			viewHolder.peoples_interestedTextView = (TextView) convertView.findViewById(R.id.interested);
			viewHolder.peoples_joinedTextView = (TextView) convertView.findViewById(R.id.joined);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		
		viewHolder.user_ImgView.setImageResource(R.drawable.defaultphoto);
		viewHolder.user_nicknameTextView.setText(mWanwans.get(pos).getUserNickname());
		viewHolder.title.setText(mWanwans.get(pos).getTitle() );
		viewHolder.timeTextView.setText(mWanwans.get(pos).getStartTime()+" --- "+mWanwans.get(pos).getEndTime());
		viewHolder.locationTextView.setText(mWanwans.get(pos).getLocation());
		viewHolder.detailsTextView.setText(mWanwans.get(pos).getDetails());
		if(mWanwans.get(pos).getDetailsImageUrl()!=null){
			viewHolder.imageView.setVisibility(View.VISIBLE);
			convertView.findViewById(R.id.wanwan_pic_bg).setVisibility(View.VISIBLE);
			viewHolder.imageView.setImageResource(R.drawable.test_wanwanlist2);
		}
		else {
			viewHolder.imageView.setVisibility(View.GONE);
			convertView.findViewById(R.id.wanwan_pic_bg).setVisibility(View.GONE);
		}
		viewHolder.days_remainTextView.setText("3");
		viewHolder.peoples_interestedTextView.setText(String.valueOf(mWanwans.get(pos).getInterested()));
		viewHolder.peoples_joinedTextView.setText(String.valueOf(mWanwans.get(pos).getJoined()));
		
		return convertView;
	}

	static class ViewHolder {
		ImageView user_ImgView;//头像
		TextView user_nicknameTextView;//昵称
		TextView timeTextView;
		TextView locationTextView;
		TextView title;//标题
		TextView detailsTextView;//详情
		ImageView imageView;//图片
		TextView days_remainTextView;//剩余天数
		TextView peoples_interestedTextView;//感兴趣人数
		TextView peoples_joinedTextView;//参加人数
		
	}
}
